package com.shengyijie.activity.tab.user;
  

import com.shengyijie.activity.MainActivity;
import com.shengyijie.activity.R;    
import com.shengyijie.activity.UserTabActivity;
import com.shengyijie.activity.share.ShareSelectActivity;
import com.shengyijie.context.ContextApplication;

import android.app.Activity; 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener; 
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class RegisterOKActivity extends Activity implements OnClickListener{ 
	  
	 private ImageButton tabHome;
	 private ImageButton tabCategory;
	 private ImageButton tabRecommended;
	 private ImageButton tabUser;
	 private ImageButton tabMore;
	 
	private Button user;
	private Button home;
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState); 
         requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
         setContentView(R.layout.registerok);
         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,      // 注意顺序
                 R.layout.title);
         initView();
    } 
    
    public void initView(){ 
    	user=(Button) this.findViewById(R.id.gouser);
    	user.setOnClickListener(this);
    	home=(Button) this.findViewById(R.id.gohome);
    	home.setOnClickListener(this);
    	
    	TextView title=(TextView) this.findViewById(R.id.title);
		title.setText("注册成功"); 
		 
    	
    	
    	tabHome=(ImageButton) this.findViewById(R.id.home);
    	tabCategory=(ImageButton) this.findViewById(R.id.category);
    	tabRecommended=(ImageButton) this.findViewById(R.id.recommended);
    	tabUser=(ImageButton) this.findViewById(R.id.user);
    	tabMore=(ImageButton) this.findViewById(R.id.more);
		try{
		    switch(ContextApplication.prePage){
		       case ContextApplication.PAGE_HOME:
		    	   tabHome.setSelected(true);
			       break;
		       case ContextApplication.PAGE_CATEGORY:
		    	   tabCategory.setSelected(true);
			       break;
		       case ContextApplication.PAGE_RECOMMENDED:
		    	   tabRecommended.setSelected(true);
			       break;
		       case ContextApplication.PAGE_USER:
		    	   tabUser.setSelected(true);
			       break;
		       case ContextApplication.PAGE_MORE:
		    	   tabMore.setSelected(true);
			       break;
		     }
		 }catch(Exception e){}
		
		 tabHome.setOnClickListener(this);
		 tabCategory.setOnClickListener(this);
		 tabRecommended.setOnClickListener(this);
		 tabUser.setOnClickListener(this);
		 tabMore.setOnClickListener(this);
    }
	@Override
	public void onClick(View v) { 
		
		Bundle bd = new Bundle();
        bd.putString("state", "exit");	
        Intent it = new Intent();
        it.putExtras(bd);
        
		switch(v.getId()){
		       case R.id.gohome:
		    	   MainActivity.tabhost.setCurrentTab(0);
				   setResult(RESULT_OK, it); 
				   this.finish();
			      break;
		       case R.id.gouser: 
		    	   if(ContextApplication.USER_TYPE==ContextApplication.USER_TYPE_PERSONAL){
		    		      Intent i=new Intent();
					      i.setClass(this, UserTabActivity.class);
					      this.startActivity(i);
					      setResult(RESULT_OK, it); 
					      this.finish(); 
		    	   }else{
		    		      Intent i=new Intent();
					      i.setClass(this, EnterpriseActivity.class);
					      this.startActivity(i);
					      setResult(RESULT_OK, it); 
					      this.finish(); 
//		    		   new AlertDialog.Builder(RegisterOKActivity.this).setTitle("提示")
//				  			    .setMessage("尊敬的生意街企业会员，您好！由于您尚未发布招商项目，请到http://www.shengyijie.net/，用注册账号登陆生意街企业中心发布招商项目。以后您可以登录生意街手机客户端，随时随地关注招商项目的最新留言情况！谢谢使用！")
//				  			    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
//				  				public void onClick(DialogInterface dialog, int whichButton) {
//				  					 
//				  				}
//				  			  }) 
//				  			  .show();
		    	   }
				   break;
			
			   case R.id.home:
				    try{
					   if(ContextApplication.prePage!=ContextApplication.PAGE_HOME){
						   MainActivity.tabhost.setCurrentTab(0);
						   setResult(RESULT_OK, it); 
						   this.finish();
					   }
				    }catch(Exception e){}
				    break;
			     case R.id.category:
					    try{
						   if(ContextApplication.prePage!=ContextApplication.PAGE_CATEGORY){
							   MainActivity.tabhost.setCurrentTab(1);
							   setResult(RESULT_OK, it); 
							   this.finish();
						   }
					    }catch(Exception e){}
					    break;
			     case R.id.recommended:
					    try{
						   if(ContextApplication.prePage!=ContextApplication.PAGE_RECOMMENDED){
							   MainActivity.tabhost.setCurrentTab(2);
							   setResult(RESULT_OK, it); 
							   this.finish();
						   }
					    }catch(Exception e){}
					    break;
			     case R.id.user:
					    try{
						   if(ContextApplication.prePage!=ContextApplication.PAGE_USER){
							   MainActivity.tabhost.setCurrentTab(3);
							   setResult(RESULT_OK, it); 
							   this.finish();
						   }
					    }catch(Exception e){}
					    break;
			     case R.id.more:
					    try{
						   if(ContextApplication.prePage!=ContextApplication.PAGE_MORE){
							   MainActivity.tabhost.setCurrentTab(4);
							   setResult(RESULT_OK, it); 
							   this.finish();
						   }
					    }catch(Exception e){}
					    break;  
		}
		
	}
	
	 @Override  
	 public boolean onKeyDown(int keyCode,KeyEvent event) {   
	    if (keyCode == KeyEvent.KEYCODE_BACK) {  
	         return true;   
	     } else
	         return super.onKeyDown(keyCode,event);   
	 }
	 
	 
	 protected void onActivityResult(int requestCode, int resultCode, Intent data) {		
		   if(requestCode==1){
				if (resultCode != RESULT_OK) {
					return;
				}
			   try{
			       String state = data.getStringExtra("state");
			       if(state.equals("exit")){
			    	   Bundle bd = new Bundle();
			           bd.putString("state", "exit");	
			           Intent it = new Intent();
			           it.putExtras(bd);
			           setResult(RESULT_OK, it); 
			    	   this.finish();
			       }
			   }
			   catch(Exception e){}
		   }
	 }
    
    
}